var app = getApp();
Page({

  data: {
    winWidth: 0,
    winHeight: 0,
    currentTab: 1,
    info:[],
    date: '',
    liyou:'',
    date2:'',
    choose:'',
    itemList: ['正常', '返工','报废'],
    status:'点击选择状态',
    userInfo: null,
    title:'',
    buttom:'',
    zhicheng:'',
    page:1,
    allpage:0,
    pagesize:50,
    more:'点击加载更多'
    
  },

  onLoad: function (options) {
    var that = this;
    wx.getSystemInfo( {
      success: function( res ) {
          that.setData( {
              winWidth: res.windowWidth,
              winHeight: res.windowHeight
          });
      }

  });

    var date = new Date();
    var jintian = date.getDate()
    //var mingtian = date.getDate()+1
     

    var todate = date.getFullYear() + "-" + ((date.getMonth() + 1) < 10 ? ("0" + (date.getMonth() + 1)) : date.getMonth()+1) + "-" + (jintian < 10 ? ("0" + jintian) : jintian);
    //var todate2 = date.getFullYear() + "-" + ((date.getMonth() + 1) < 10 ? ("0" + (date.getMonth() + 1)) : date.getMonth()+1) + "-" + (mingtian < 10 ? ("0" + mingtian) : mingtian);
    var date2 = new Date();
    date2.setTime(date2.getTime()+24*60*60*1000);
    var mtyear = date2.getFullYear();
    var mtmonth = (date2.getMonth()+1) < 10 ? ("0" + (date2.getMonth()+1)) : date2.getMonth()+1;
    var mtday = (date2.getDate()) < 10 ? ("0" + (date2.getDate())) : date2.getDate();
    var todate2 =  mtyear + "-" + mtmonth + "-" + mtday;

    that.setData({ date: todate});
    that.setData({ date2: todate2});


  },
  onShow:function(){
    var that = this;
    that.setData( { 
      page: 1 ,
      info:[]
    });
    that.getlist()
  },

  moredata:function(){
    var that = this;
    if(that.data.more == "已全部加载"){
      return false;
    }
    this.getlist()
  },
  swichNav: function( e ) {
    var that = this;
    if( this.data.currentTab === e.target.dataset.current ) {
        return false;
    } else {
        that.setData( {
            currentTab: e.target.dataset.current
        })
        that.setData( { page: 1 });
        that.setData( { info: [] });
        that.getlist();
    }
 
},

bindChange: function( e ) {

    var that = this;
    that.setData( { currentTab: e.detail.current });

},


  godetail: function(e) {
 
        console.log(e.currentTarget.dataset.fee)
        wx.navigateTo({
          url: '/page/my/details?id='+e.currentTarget.dataset.fee,
        });
  },

  bindDateChange: function(e) {
    var that = this;
    console.log('picker发送选择改变，携带值为', e.detail.value)
    that.setData({
      date: e.detail.value
    })
    that.setData( { page: 1 });
    that.setData( { info: [] });
    that.getlist()
  },
  bindDateChange2: function(e) {
    var that = this;
    console.log('picker发送选择改变，携带值为', e.detail.value)
    that.setData({
      date2: e.detail.value
    })
    that.setData( { page: 1 });
    that.setData( { info: [] });
    that.getlist()
  },




  getlist:function (){
    var that = this
    wx.request({
      url: app.apiUrl + '/api/data/mylist',
      data: {
        page:that.data.page,
        pagesize:that.data.pagesize,
        sdate:this.data.date,
        edate:this.data.date2,
        groupid:wx.getStorageSync('groupid'),
        openid:wx.getStorageSync('openid'),
        type:that.data.currentTab
      },
      method: 'post',
      header: {
        "Content-Type": "application/x-www-form-urlencoded",
      },
      success: function (res) {
        if(res.data.code == 1){
          var data = that.data.info;
          var newdata = data.concat(res.data.data.rows) ;
          that.setData({ info: newdata});
          that.setData({ allpage: res.data.data.allpage});
          that.setData({ page: newdata});
          if(res.data.data.allpage == res.data.data.page){
            that.setData({ more: '已全部加载'});
          }else{
            var nextpage = parseInt(res.data.data.page) + 1;
            that.setData({ page: nextpage});
            that.setData({ more: '点击加载更多'});
          }  

        }else{
          that.setData({ page: 1});
          that.setData({ more: '暂无数据'});
          wx.showModal({
                 content: res.data.msg,
                 showCancel: false
            });
            that.setData({ info: ''});
        }
     
      }
    });
  },
  
})